package com.jic.manager.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.RegionMapper;
import com.jic.manager.entity.Region;
import com.jic.manager.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 销售区域表
 * @author : 
 * @email : 
 * @since : 2020-02-08 05:59:10
 * @version : v1.0.0
 */
@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    private RegionMapper regionMapper;

    @Override
    public long insert(Region region) {
        long flag = regionMapper.insert(region);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return regionMapper.delete(id);
    }

    @Override
    public long update(Region region) {
        return regionMapper.update(region);
    }

    @Override
    public Region queryByPrimaryKey(Long id){
        return regionMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<Region> query(Region region){
        return regionMapper.query(region);
    }

    @Override
    public PageResult<Region> queryPage(Region region, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<Region> list = regionMapper.queryPage(startIndex, pageQuery.getLimit(), region);
        long count = regionMapper.queryPageCount(region);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}